﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using Snake.Core;
using Snake.SQL;
using Snake.SQL.SQLNode;

namespace Snake.SQLBuilder.SQLNode
{
    public class IN : IExprNode
    {
        public DbOperate _Operate;
        public IEnumerable<object> ids; 
        public  IN(DbOperate operate,IEnumerable<object> ids )
        {
            _Operate = operate;
            this.ids = ids;
        }

        public void Render(SQLWriter writer)
        {
            var result = string.Empty;
            foreach (var id in ids)
            {
                if (string.IsNullOrEmpty(result))
                    result ="'"+ id+"'";
                result =result+ "," + "'"+id+"'";

            }
            writer.AppendLine( _Operate.EntityMap.Table+_Operate.EntityMap.Key.Column.Raw,SQLStrings.IN);
            writer.Append("(",result,")");
          
        }

        public Precedence Precedence
        {
            get { return Precedence.High; }
        }
    }
}
